package com.shu.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;

//@Aspect
//@Component
public class TimeAspect {

//    @Before()  之前
//    @After()   之后
//    @AfterThrowing  抛出异常
//    @Around()   覆盖之前三种

    //UserController 里面所有的方法都有效果
    @Around("execution(* com.shu.controller.UserController.*(..))")
    public Object handlerControllerMethod(ProceedingJoinPoint pjp) throws Throwable {

        System.out.println("time Aspect start");
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            System.out.println(" arg is "+ arg);
        }
        Long startTime = System.currentTimeMillis();
        Object proceed = pjp.proceed();
        System.out.println(proceed);
        System.out.println("time Aspect 耗时" + (System.currentTimeMillis()-startTime));
        System.out.println("time Aspect end");
        return proceed;
    }
}
